package ide.modelo;

import java.util.ArrayList;

public class Pipeline {
	private ArrayList<String> lineasEditorParseadas;

	public Pipeline() {
	}

	public void setLineasEditorParseadas(ArrayList<String> lineasPasadas) {
		String aux;
		int j = 0;
		lineasEditorParseadas = new ArrayList<String>();

		for (int i = 0; i < lineasPasadas.size(); i++) {
			aux = lineasPasadas.get(i);
			aux = aux.trim();

			if (!aux.isEmpty()) {
				String[] partes = aux.split(" ");
				if(partes[0].equals("parar") || (partes[0].length()==4)){
					aux = partes[0];
				}else{
					aux = partes[0] + " " + partes[1];
				}
				lineasEditorParseadas.add(j, aux);
				j++;
			}
		}
	}

	public String getInstruccion(int programCounter) {
		programCounter = programCounter / 2;
		return lineasEditorParseadas.get(programCounter);
	}

	public ArrayList<String> getProximasInstrucciones(int programCounter) {
		ArrayList<String> proximasInstrucciones = new ArrayList<String>();
		programCounter = programCounter / 2;

		String instruccionActual = lineasEditorParseadas.get(programCounter);
		if (!instruccionActual.split(" ", 2)[0].equals("sal")) {
			for (int i = 1; i < 4; i++) {
				try {
					String linea = lineasEditorParseadas.get(programCounter + i);
					proximasInstrucciones.add(linea);
					if (linea.split(" ", 2)[0].equals("sal")) {
						break;
					}
				} catch (Exception e) {
				}
			}
		}
		return proximasInstrucciones;
	}

}
